package com.test.java;

import java.util.Scanner;

/**
 * 本题要求编写程序，计算2个有理数的和、差、积、商。
 * =============================================================
 * Version          Author          Date            Description
 * 1.0              白建         2017/12/28             创建
 * =============================================================
 */
public class Java_25
{

    public static void main(String[] args)
    {

        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();
        String[] strings = input.split(" ");

        int[] A = new int[2];
        int[] B = new int[2];
        String[] stringsTemp;

        stringsTemp = strings[0].split("/");
        A[0] = Integer.parseInt(stringsTemp[0]);
        A[1] = Integer.parseInt(stringsTemp[1]);
        stringsTemp = strings[1].split("/");
        B[0] = Integer.parseInt(stringsTemp[0]);
        B[1] = Integer.parseInt(stringsTemp[1]);

        add(A, B);
        subtract(A, B);
        multiply(A, B);
        divide(A, B);
    }

    private static void add(int[] a, int[] b)
    {

        int[] result = new int[2];
        result[0] = (a[0] * b[1]) + (a[1] * b[0]);
        result[1] = a[1] * b[1];
        System.out.println(format(a) + " + " + format(b) + " = " + format(result));
    }

    private static void subtract(int[] a, int[] b)
    {

        int[] result = new int[2];
        result[0] = (a[0] * b[1]) - (a[1] * b[0]);
        result[1] = a[1] * b[1];
        System.out.println(format(a) + " - " + format(b) + " = " + format(result));
    }

    private static void multiply(int[] a, int[] b)
    {

        int[] result = new int[2];
        result[0] = a[0] * b[0];
        result[1] = a[1] * b[1];
        System.out.println(format(a) + " * " + format(b) + " = " + format(result));
    }

    private static void divide(int[] a, int[] b)
    {

        int[] result = new int[2];
        result[0] = a[0] * b[1];
        result[1] = a[1] * b[0];
        if ("0".equalsIgnoreCase(format(b)))
        {
            System.out.println(format(a) + " / " + format(b) + " = Inf");
        }
        else
        {
            System.out.println(format(a) + " / " + format(b) + " = " + format(result));
        }
    }

    private static String format(int[] original)
    {

        int[] current = new int[2];
        int GCD;
        if (original[0] == 0)
        {
            return "0";
        }
        else if (maxGCD(original[0], original[1]) != 1)
        {
            GCD = maxGCD(original[0], original[1]);
            current[0] = original[0] / GCD;
            current[1] = original[1] / GCD;
            return format(current);
        }
        else if (original[0] % original[1] == 0)
        {
            return original[0] / original[1] > 0 ?
                    original[0] / original[1] + "" :
                    "(" + original[0] / original[1] + ")";
        }
        else
        {
            if (Math.abs(((double) original[0]) / original[1]) > 1 && ((double) original[0]) / original[1] > 0)
            {
                return original[0] / original[1] + " " + (original[0] - ((original[0] / original[1]) * original[1]))
                        + "/" + original[1];
            }
            if (Math.abs(((double) original[0]) / original[1]) >= 1 && ((double) original[0]) / original[1] < 0)
            {
                return "(" + original[0] / original[1] + " " + Math.abs(
                        original[0] - ((original[0] / original[1]) * original[1])) + "/" + Math.abs(original[1]) + ")";
            }
            if (Math.abs(((double) original[0]) / original[1]) < 1 && ((double) original[0]) / original[1] > 0)
            {
                return original[0] + "/" + original[1];
            }
            if (Math.abs(((double) original[0]) / original[1]) < 1 && ((double) original[0]) / original[1] < 0)
            {
                return "(-" + Math.abs(original[0]) + "/" + Math.abs(original[1]) + ")";
            }
        }
        return "";
    }

    private static int maxGCD(int a, int b)
    {

        int temp;
        a = Math.abs(a);
        b = Math.abs(b);
        if (a < b)
        {
            temp = b;
            b = a;
            a = temp;
        }
        if (a % b == 0)
        {
            return b;
        }
        else
        {
            temp = a % b;
            a = b;
            b = temp;
            return maxGCD(a, b);
        }
    }
}
